package com.big.app.task;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.big.app.config.RedisConfig;
import com.big.app.dao.FoodTypeDao;
import com.big.app.dao.MessagesDao;
import com.big.app.dao.SightDao;
import com.big.app.dto.FoodsDto;
import com.big.app.dto.MessagesDto;
import com.big.app.dto.SightDto;
import com.big.app.entity.FoodType;
import com.big.app.util.JedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class TopTask {
    @Autowired
    private FoodTypeDao dao;
    @Autowired
    private MessagesDao messagesDao;
    @Resource
    private SightDao dao1;
    //实例化日志对象
    private Logger logger= LoggerFactory.getLogger(TopTask.class);

    //每日更新一次类型更新 每次凌晨3点执行方法
    @Scheduled(cron = "0 0 3 * * ?")
    public void syncSkill(){

        List<FoodType> foodTypes = dao.selectList(null);
        JedisUtils.setStr(RedisConfig.FOOD_TYPE, JSON.toJSONString(foodTypes));
    }

    //每日更新一次热门商品 每天凌晨4点
    @Scheduled(cron = "0 0 4 * * ?")
    public void syncSightHot(){
        logger.info("定时任务，定时更新热门景点-开始");
        List<SightDto> list=dao1.queryHotTop();
        //更新缓存
        JedisUtils.setStr(RedisConfig.HOT_SIGHT, JSON.toJSONString(list));
        logger.info("定时任务，定时更新热门景点-结束");
    }

    //每日更新一次热门商品 每天凌晨2点40
    @Scheduled(cron = "0 40 2 * * ?")
    public void syncGoods(){
        logger.info("定时任务，定时更新热门商品-开始");
        List<MessagesDto> list=messagesDao.selectHotTop(4);
        //更新缓存
        JedisUtils.setStr(RedisConfig.Messages_HOT,JSON.toJSONString(list));
        logger.info("定时任务，定时更新热门商品-结束");
    }
}
